package com.liuyang.controller;

import com.liuyang.common.Result;
import com.liuyang.common.TableResult;
import com.liuyang.entity.MaterialManagement;
import com.liuyang.service.MaterialManagementService;
import com.liuyang.vo.InsterMaterialManagementVo;
import com.liuyang.vo.UpdateMaterialManagement;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/system/management")
public class MaterialManagementController {

    /**
     * 注入服务层
     */
    @Resource
    private MaterialManagementService managementService;

    /**
     * 物资入库
     */
    @PostMapping("/add")
    public Result Warehousing(@RequestBody InsterMaterialManagementVo vo){

        String warehousing = managementService.warehousing(vo);
        return Result.succ(warehousing);
    }
    /**
     * 物资出库
     */
    @PutMapping("/update")
    public Result Outbound(@RequestBody UpdateMaterialManagement updateMaterialManagement){
        String outbound = managementService.outbound(updateMaterialManagement);
        return Result.succ(outbound);
    }

    /**
     * 过期时间进行更新
     * @return
     */
    @PutMapping("/update/time")
    public Result updateByTime(String expirtTime,String materialsName){
        String updateByTime = managementService.updateByTime(expirtTime, materialsName);
        return Result.succ(updateByTime);
    }
    /**
     * 物资入库查询
     */
    @GetMapping("/page")
    public Result getAll(@RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10")Integer pageSize,
                              @RequestParam(required = false) String type){
        List<MaterialManagement> all = managementService.getAll(page, pageSize, type);
        return Result.succ(all);
    }
    /**
     * 物资入库查询
     */
    @GetMapping("/page/source")
    public Result getBySource(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10")Integer pageSize,
                         @RequestParam(required = false) String type){
        List<MaterialManagement> all = managementService.getBySource(page, pageSize, type);
        return Result.succ(all);
    }
    /**
     * 物资入库查询
     */
    @GetMapping("/page/destination")
    public Result getByDestination(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10")Integer pageSize,
                         @RequestParam(required = false) String type){
        List<MaterialManagement> all = managementService.getByDestination(page, pageSize, type);
        return Result.succ(all);
    }
}
